Date.prototype.format = function(fmt) {
    var o = {
        "M+" : this.getMonth()+1,                 //月份
        "d+" : this.getDate(),                    //日
        "h+" : this.getHours(),                   //小时
        "m+" : this.getMinutes(),                 //分
        "s+" : this.getSeconds(),                 //秒
        "q+" : Math.floor((this.getMonth()+3)/3), //季度
        "S"  : this.getMilliseconds()             //毫秒
    };
    if(/(y+)/.test(fmt)) {
        fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
    }
    for(var k in o) {
        if(new RegExp("("+ k +")").test(fmt)){
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
        }
    }
    return fmt;
}

//获取id
var ss= getUrlParam('id');

//获取url中的参数
function getUrlParam(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
    var r = window.location.search.substr(1).match(reg);  //匹配目标参数
    if (r != null) return unescape(r[2]); return null; //返回参数值
}
var ty={

        pageNum:1,
        pageSize: 3,
        id:ss
}


var vm=new Vue({
    el:"#ljw",
    data:{
        pid:'',
        supname:"",
        time:'',
        single:'',
        woseId:'',
        paidMoney:'',
        daifukuan:'',
        log:'',
        listPl:[],
        deliveryDate:"",
        remark:"",
        zhuangtai:"",
        listrk:"",
        orderMoney: 0,
        supplierId:0,
        wid:"",
    },
    methods:{
        showPo(){
            axios.get('/purchase/show1Po',{
                params:{
                    pid:ss
                }
            }).then(response=>{
                var dto=response.data
                console.log(dto)
                vm.pid=dto.obj.pid
                vm.supname=dto.obj.supname
                vm.time=dto.obj.deliveryDate
                vm.single=dto.obj.single
                vm.woseId=dto.obj.wname
                vm.wid=dto.obj.woseId
                vm.paidMoney=dto.obj.paidMoney
                vm.daifukuan=(dto.obj.orderMoney-dto.obj.paidMoney)
                vm.log=dto.obj.log
                vm.deliveryDate=dto.obj.deliveryDate
                vm.remark=dto.obj.remark
                vm.zhuangtai=dto.obj.orderStaId
                vm.orderMoney = dto.obj.orderMoney
                vm.supplierId=dto.obj.supplierId
                if (dto.obj.orderStaId!=1){
                    $("#tj").attr("style","display:none;")
                }
            })
        },
        showPl(){
            axios.get('/purchase/listPl',{
                params: {
                    pid:ss,
                }
            }).then(res=>{
                vm.listPl=res.data.obj
                console.log(vm.listPl)
            }).catch(err=>{

            })
        },
        tj(){
            var on={
                id:this.pid,
                orderStaId:5
            }
            JSON.stringify(on)
            axios.post('/purchase/updaPo2/',on,{
                'Content-Type':'multipart/form-data'
            }).then(res=>{
                var js={
                    relCode:this.pid,
                    type:21,
                    status:2,
                    houseId:vm.wid,
                    single:getCookie(),
                    subDate:new Date().format("yyyy-MM-dd hh:mm:ss"),
                    preDate:vm.deliveryDate, //预计时间
                    remark:vm.remark
                }
                var json={
                    stock_order:js,
                    list:vm.listPl
                }
                // JSON.stringify(json)
                axios.post('/wares/addStock_order',json).then(res=>{
                    alert("提交成功")
                    location.reload();
                })




            })
        },
        isShow(v){
            for (var i=2;i<quan.length;i++){
                if (v==quan[i])return true
            }
            return false
        },
        ruku(){
            var qa={
                id:this.pid,
                orderStaId:15
            }
            JSON.stringify(qa)
            axios.post('/purchase/updaPo2',qa,{
                'Content-Type':'multipart/form-data'
            }).then(res=>{
                var crk={
                    relCode:this.pid,
                    pageNum:1,
                    pageSize:1,
                }
                JSON.stringify(crk)
                axios.post('/wares/getStock_order',crk,{
                    'Content-Type':'multipart/form-data'
                }).then(res=>{
                    console.log(res.data)
                    vm.listrk=res.data.obj.list
                    var code=vm.listrk[0].code
                    var rk={
                        bStatus:vm.zhuangtai,
                        status:15,
                        code:code,
                        type:21,
                        single:getCookie(),
                        subDate:new Date().format("yyyy-MM-dd hh:mm:ss"),
                        verifier:getCookie(),
                        verifyDate:new Date().format("yyyy-MM-dd hh:mm:ss"),
                    }
                    JSON.stringify(rk)
                    axios.post('/wares/nextStock_order',rk,{
                        'Content-Type':'multipart/form-data'
                    }).then(res=>{
                        var json={
                            relcode:this.pid,
                            payee:this.supplierId,
                            amount:this.orderMoney,
                            single:getCookie(),
                            type:5,
                            account:1,
                            status:2,
                            payDate:this.deliveryDate,
                            remark:"这是点击入库生成的付款单",
                        }
                        var data = new FormData()
                        data.append('json',JSON.stringify(json))
                        axios.post('/finance/addPay_order',data,{
                            'Content-Type':'multipart/form-data'
                        }).then(res=>{
                            alert("入库成功")
                            location.reload();
                        })
                    })
                }).catch(err=>{
                    alert("没有找到入库单")
                })
            })
        }




        },
    mounted() {
        this.showPo()
        this.showPl()
    }
})

